#include <bits/stdc++.h>
using namespace std;
long long a[200001], s[200002];
long long ans = 0, n;
void dfs(long long sum, int k, int t1, int t2)
{
    if (k > n || sum + s[k] <= ans)
    {
        ans = max(ans, sum);
        return;
    }
    if (t1 == a[k])
    {
        dfs(sum + (t1 == a[k]) * a[k], k + 1, a[k], t2);
        return;
    }
    if (t2 == a[k])
    {
        dfs(sum + (t2 == a[k]) * a[k], k + 1, t1, a[k]);
        return;
    }
    dfs(sum + (t1 == a[k]) * a[k], k + 1, a[k], t2);
    dfs(sum + (t2 == a[k]) * a[k], k + 1, t1, a[k]);
}
int main()
{
    freopen("color.in", "r", stdin);
    freopen("color.out", "w", stdout);
    int t;
    cin >> t;
    while (t--)
    {
        ans = 0;
        cin >> n;
        for (int i = 1; i <= n; i++)
        {
            cin >> a[i];
        }
        for (int i = n; i >= 1; i--)
        {
            s[i] = s[i + 1] + a[i];
        }
        dfs(0, 1, 0, 0);
        cout << ans << endl;
    }
    return 0;
}

